﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/**
 * 创建时间：2014/11/18 15:09:41
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace CUWo.Common.StorageHelper
{
    public interface IStorageHelper
    {
        #region 同步方法
        Stream ReadFile(string filePath);

        string ReadText(string filePath);

        void WriteFile(Stream stream, string filePath, bool replace = false);

        void WriteFile(byte[] data, string filePath, bool replace = false);

        void WriteText(string text, string filePath, bool replace = false);

        bool FileExists(string filePath);

        bool DirectoryExists(string directory);

        bool DeleteFile(string filePath);

        bool DeleteDirectory(string directory, bool isDeleteAll = false);

        bool CreateDirectory(string directory);

        long GetFileLength(string filePath);

        string[] GetFiles(string directory);

        string[] GetDirectories(string directory);

        /// <summary>
        /// 序列号类到文件（Xml）
        /// </summary>
        void Serialize<T>(string filePath, T obj);

        T DeSerialize<T>(string filePath);

        void CopyPackageFileToLocal(string source, string target = null, bool replace = false);

        void CopyPackageFolderToLocal(string source, string target = null, bool replace = false);

        Stream GetResourceStream(string filePath);

        #endregion

        #region 异步方法

        Task<Stream> ReadFileAsync(string filePath);

        Task<string> ReadTextAsync(string filePath);

        Task WriteFileAsync(Stream stream, string filePath, bool replace = false);

        Task WriteFileAsync(byte[] data, string filePath, bool replace = false);

        Task WriteTextAsync(string text, string filePath, bool replace = false);

        Task<bool> FileExistsAsync(string filePath);

        Task<bool> DirectoryExistsAsync(string directory);

        Task<bool> DeleteFileAsync(string filePath);

        Task<bool> DeleteDirectoryAsync(string directory, bool isDeleteAll = false);

        Task<bool> CreateDirectoryAsync(string directory);

        Task<ulong> GetFileLengthAsync(string filePath);

        Task<string[]> GetFilesAsync(string directory);

        Task<string[]> GetDirectoriesAsync(string directory);

        Task SerializeAsync<T>(string filePath, T obj);

        Task<T> DeSerializeAsync<T>(string filePath);

        /// <summary>
        /// 拷贝安装目录的文件到本地
        /// </summary>
        Task CopyPackageFileToLocalAsync(string source, string target = null, bool replace = false);

        /// <summary>
        /// 拷贝安装目录的文件夹（包括子文件夹和子文件）到本地
        /// </summary>
        Task CopyPackageFolderToLocalAsync(string source, string target = null, bool replace = false);

        Task<Stream> GetResourceStreamAsync(string filePath);

        #endregion

    }
}
